config := meta.(*Config)

// current import_formats cannot import fields with forward slashes in their value
if err := parseImportId([]string{"(?P<name>.+)"}, d, config); err != nil {
	return nil, err
}

nameParts := strings.Split(d.Get("name").(string), "/")
if len(nameParts) == 6 {
	// `projects/{{project}}/locations/{{location}}/namespaces/{{namespace_id}}`
	if err := d.Set("project", nameParts[1]); err != nil {
		return nil, fmt.Errorf("Error setting project: %s", err)
	}
	if err := d.Set("location", nameParts[3]); err != nil {
		return nil, fmt.Errorf("Error setting location: %s", err)
	}
	if err := d.Set("namespace_id", nameParts[5]); err != nil {
		return nil, fmt.Errorf("Error setting namespace_id: %s", err)
	}
} else if len(nameParts) == 3 {
	// `{{project}}/{{location}}/{{namespace_id}}`
	if err := d.Set("project", nameParts[0]); err != nil {
		return nil, fmt.Errorf("Error setting project: %s", err)
	}
	if err := d.Set("location", nameParts[1]); err != nil {
		return nil, fmt.Errorf("Error setting location: %s", err)
	}
	if err := d.Set("namespace_id", nameParts[2]); err != nil {
		return nil, fmt.Errorf("Error setting namespace_id: %s", err)
	}
	id := fmt.Sprintf("projects/%s/locations/%s/namespaces/%s", nameParts[0], nameParts[1], nameParts[2])
	if err := d.Set("name", id); err != nil {
		return nil, fmt.Errorf("Error setting name: %s", err)
	}
	d.SetId(id)
} else if len(nameParts) == 2 {
	// `{{location}}/{{namespace_id}}`
	project, err := getProject(d, config)
	if err != nil {
			return nil, err
	}
	if err := d.Set("project", project); err != nil {
		return nil, fmt.Errorf("Error setting project: %s", err)
	}
	if err := d.Set("location", nameParts[0]); err != nil {
		return nil, fmt.Errorf("Error setting location: %s", err)
	}
	if err := d.Set("namespace_id", nameParts[1]); err != nil {
		return nil, fmt.Errorf("Error setting namespace_id: %s", err)
	}
	id := fmt.Sprintf("projects/%s/locations/%s/namespaces/%s", project, nameParts[0], nameParts[1])
	if err := d.Set("name", id); err != nil {
		return nil, fmt.Errorf("Error setting name: %s", err)
	}
	d.SetId(id)
} else {
	return nil, fmt.Errorf(
		"Saw %s when the name is expected to have shape %s, %s or %s",
		d.Get("name"),
		"projects/{{project}}/locations/{{location}}/namespaces/{{namespace_id}}",
		"{{project}}/{{location}}/{{namespace_id}}",
		"{{location}}/{{namespace_id}}")
}
return []*schema.ResourceData{d}, nil
